Install/load necessary R packages
Set date range
min_year = 2017
max_year = 2021
More information about peatland and upland water elevation data collected at the Marcell Experimental Forest can be found on the Environmental Data Initiative Repository Portal.
Read in the most up-to-date data from the following Box file
path:
External-MEF_DATA/Hydro/WaterTableElevation/Bogwells/L1
External-MEF_DATA/EDI/peatland_water_table_daily/edi.562.2/data_objects/Clean the data into a tidy format
#set file path to read in data from Box
filepath = "/Users/miaforsline/Library/CloudStorage/Box-Box/External-MEF_DATA/Hydro/WaterTableElevation/Bogwells/L1"
#read in the raw data
bogwell <- read_csv(here(filepath, "L1_Peatland_well_daily_history_2021forMia.csv"))
#clean the data
##note: we do not want any E values for the flag column
bogwell_clean <- bogwell %>%
clean_names() %>%
mutate(year = format(as.POSIXct(date, format = '%Y-%m-%d',
tz = "GMT"),
format = '%Y'),
year = as.numeric(year)) %>%
subset(year >= min_year & year <= max_year)
#save clean data CSV to use in future RMD files
write.csv(x = bogwell_clean,
file = file.path(here("intermediate_data", "bogwell_clean.csv")),
row.names = FALSE)
bogwell_clean_s2 <- bogwell_clean %>%
subset(peatland == "S2")
#plot
p_bogwell_s2 <- ggplot(data = bogwell_clean_s2) +
geom_line(aes(x = date,
y = wte,
group = 1,
text = paste0("Date: ", date, "\n",
"Water Table Elevation (m): ", wte))) +
theme_classic() +
labs(x = "Time",
y = "Water Table Elevation (m above sea level)",
title = paste0("S2 Daily Peatland Water Table Elevation (", min_year, "-", max_year, ")")
) +
theme(plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5,
size = 7))
#interactive plot
ggplotly(p_bogwell_s2,
tooltip = "text")
bogwell_clean_s2 %>%
#remove rows that have NA wte values
filter(!is.na(wte)) %>%
summarise(mean_wte_m = round(mean(wte), digits = 3),
max_wte_m = max(wte),
min_wte_m = min(wte),
sd_wte_m = round(sd(wte), digits = 3)
) %>%
#t() %>%
kable(caption = "S2 Stripchart Bogwell Statistics",
col.names = c("Mean WTE (m)",
"Max WTE (m)",
"Min WTE (m)",
"SD")) %>%
kable_material(c("striped", "hover"))
| Mean WTE (m) | Max WTE (m) | Min WTE (m) | SD |
|---|---|---|---|
| 421.88 | 422.15 | 421.48 | 0.095 |
Function for loading Campbell DataLogger .dat files:
readCDL = function(file){
# read data file starting on 5th line
dat <- read.csv(file, sep=",",header=FALSE,skip=4,na.strings="NAN",stringsAsFactors=F)
# Read in just the header line (l2)
# unlist the line, and remove quotes
h <- readLines(file, n=2)[2]
n <- as.factor(unlist(strsplit(h, ",")) )
n2 <- gsub('"', "", n)
# assign column names to dataframe
colnames(dat) = n2
return(dat)
}
Constants to convert between feet and meters:
MetersPerFoot = 0.3048
FeetPerMeter = 3.28048
min_year = 2020
max_year = 2021
Read in the data from the following Box file path:
External-MEF_DATA/DataDump/RealTimeData
Clean the data into a tidy format
MaxWTElev column#set file path to read in data from Box
filepath = "/Users/miaforsline/Library/CloudStorage/Box-Box/External-MEF_DATA/DataDump/RealTimeData"
#read in the raw data
s2_se <- readCDL(file = here(filepath, "S2_bogwell_S2BW_Daily.dat"))
s2_se_clean <- s2_se %>%
clean_names() %>%
#select relevant columns
select(timestamp,
max_wt_elev) %>%
#rename columns
rename(datetime = timestamp,
max_wt_elev_ft = max_wt_elev) %>%
#reformat columns into appropriate classes
mutate(datetime = as.POSIXct(datetime, format = '%Y-%m-%d %H:%M:%S',
tz = "GMT"),
max_wt_elev_ft = as.numeric(max_wt_elev_ft),
max_wt_elev_m = max_wt_elev_ft * MetersPerFoot)
#plot
p_s2 <- ggplot(data = s2_se_clean) +
geom_line(aes(x = datetime,
y = max_wt_elev_m,
group = 1,
text = paste0("Date: ", datetime, "\n",
"Water Table Elevation (m): ", max_wt_elev_m))) +
theme_classic() +
labs(x = "Time",
y = "Water Table Elevation (m)",
title = paste0("S2 Bogwell Water Table Elevation (", min_year, "-", max_year, ")")
) +
theme(plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5))
#interactive plot
ggplotly(p_s2,
tooltip = "text")
s2_se_clean %>%
#rename columns
rename(wte = max_wt_elev_m) %>%
#remove rows that have NA wte values
filter(!is.na(wte)) %>%
summarise(mean_wte_m = round(mean(wte), digits = 3),
max_wte_m = max(wte),
min_wte_m = min(wte),
sd_wte_m = round(sd(wte), digits = 3)
) %>%
#t() %>%
kable(caption = "S2 Shaft Encoder Bogwell Statistics",
col.names = c("Mean WTE (m)",
"Max WTE (m)",
"Min WTE (m)",
"SD")) %>%
kable_material(c("striped", "hover"))
| Mean WTE (m) | Max WTE (m) | Min WTE (m) | SD |
|---|---|---|---|
| 421.844 | 422.0916 | 421.4854 | 0.115 |
Note that this file is being knit as index.html
into the climate_bogwell
repository in order to update the GitHub pages
website, where the plots can be viewed online.